﻿Imports System.Text
Imports System.Net
Imports System.Web
Imports System.IO
Imports System.Linq
 
Imports Google.GData.Client
Imports Google.GData.Extensions
Imports Google.GData.Spreadsheets

Public Class Form1

    Sub sp1()
        Dim service = New SpreadsheetsService("exampleCo-exampleApp-1")
        service.setUserCredentials("mnsrulz@gmail.com", "9899888450")
        Dim q = New CellQuery("https://spreadsheets.google.com/feeds/cells/tI2_viTWI9ODnwddeX0yEgQ/od6/private/full") '("https://spreadsheets.google.com/feeds/spreadsheets/private/full/tI2_viTWI9ODnwddeX0yEgQ")
        With q
            .MinimumColumn = 1
            .MaximumColumn = 2
            .MinimumRow = 2
            .MaximumRow = 5
        End With

        Dim cellFeed = service.Query(q)

        Sp()



    End Sub

    Sub Sp()

        Dim service = New SpreadsheetsService("exampleCo-exampleApp-1")
        service.setUserCredentials("mnsrulz@gmail.com", "9899888450")

        Dim query = New SpreadsheetQuery() '("https://spreadsheets.google.com/feeds/spreadsheets/private/full/tI2_viTWI9ODnwddeX0yEgQ")

        '		Content	"https://spreadsheets.google.com/feeds/spreadsheets/private/full/tI2_viTWI9ODnwddeX0yEgQ"	String




        Dim feed = service.Query(query)

        Dim en = feed.Entries



        Dim link = en(0).Links.FindService(GDataSpreadsheetsNameTable.WorksheetRel, Nothing)
        Dim WSquery = New WorksheetQuery(link.HRef.ToString())
        Dim WSfeed = service.Query(WSquery)


        Dim listFeedLink = WSfeed.Entries(0).Links.FindService(GDataSpreadsheetsNameTable.ListRel, Nothing)
        Dim LFquery = New ListQuery(listFeedLink.HRef.ToString())
        Dim LFfeed = service.Query(LFquery)
        Dim WSRow As ListEntry = LFfeed.Entries(0)
        Dim elements = WSRow.Elements




        Dim rnd As New Random

        Dim timespan As New TimeSpan
        Dim prevTime As Date
        For ckckc = 1 To 10000

            prevTime = Now
            Dim newRow = New ListEntry()
            For Each i As ListEntry.Custom In elements
                Dim curElement = New ListEntry.Custom()
                curElement.LocalName = i.LocalName
                curElement.Value = Guid.NewGuid.ToString
                newRow.Elements.Add(curElement)
            Next

            LFfeed.Insert(newRow)
            Console.WriteLine("inserted: {0}, TotalMillisecs: {1}", ckckc, Now.Subtract(prevTime).TotalMilliseconds)

        Next






        Dim cellFeedLink = WSfeed.Entries(0).Links.FindService(GDataSpreadsheetsNameTable.CellRel, Nothing)
        Dim Cellquery = New CellQuery(cellFeedLink.HRef.ToString())
        With Cellquery
            .MinimumColumn = 1
            .MaximumColumn = 2
            .MinimumRow = 2
            .MaximumRow = 5
        End With

        Dim Cellfeed = service.Query(Cellquery)
        Dim lst = Cellfeed.Entries


        'AtomLink cellFeedLink = entry.Links.FindService(GDataSpreadsheetsNameTable.CellRel, null);

        '    CellQuery query = new CellQuery(cellFeedLink.HRef.ToString());
        '    query.MinimumColumn = 1;
        '    query.MaximumColumn = 1;
        '    query.MinimumRow = 2;

        '    CellFeed feed = service.Query(query);
        '    Console.WriteLine();
        '    Console.WriteLine("Cells in column 1:");
        '    foreach (CellEntry curCell in feed.Entries)
        '    {
        '        Console.WriteLine("Row {0}: {1}", curCell.Cell.Row, curCell.Cell.Value);
        '    }













        'AtomLink link = entry.Links.FindService(GDataSpreadsheetsNameTable.WorksheetRel, null);

        '    WorksheetQuery query = new WorksheetQuery(link.HRef.ToString());
        '    WorksheetFeed feed = service.Query(query);



        'SpreadsheetQuery query = new SpreadsheetQuery();
        '    SpreadsheetFeed feed = service.Query(query);



        'SpreadsheetsService service = new SpreadsheetsService("exampleCo-exampleApp-1");
        '    service.setUserCredentials(userName, password);




    End Sub


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        sp1()



        'Dim p = "F:\MyRobots\MyRobots\SendSMS\Ignou\Completed\"
        'Dim rn As New Random

        'For A As Integer = 1 To 30

        '    Dim f = System.IO.Directory.CreateDirectory(p & Now.Ticks).FullName
        '    For i As Integer = 0 To 1000
        '        System.IO.File.Create(f & "\" & rn.Next(12345678, 98765432) & ".txt").Close()
        '    Next
        'Next




        'Dim l = fetchRCCodes()

        'Dim o = (From t In l Select fetchRCECCodes(t)).ToList

        'Dim lst As New List(Of String)

        'For Each ecc In o

        '    For Each tc In ecc.ECCode
        '        lst.Add(tc)
        '    Next
        'Next


        'Dim ooocco = String.Join(",", lst.ToArray)

        'Dim f = My.Computer.FileSystem.ReadAllText("F:\Enjoy (F)\Manish Documents\bca_ignou\Enrollment for Dec 09 Mout Abu.txt")

        'Dim rx = System.Text.RegularExpressions.Regex.Matches(f, "\d{9}")

        'Dim s = String.Join(",", (From t As RegularExpressions.Match In rx Select t.Value).ToArray)



        'Dim o As New System.Collections.Specialized.NameValueCollection
        'o.Add("EnrNo", "063073578")
        'o.Add("Submit", "Submit")
        'o.Add("program", "BCA")

        'Dim r = GetRequest("http://admission.ignou.ac.in/changeadmdata/ADDRESSSTATUS.ASP", o)

        'Dim resp = r.GetResponse.GetResponseStream
        'Dim reader As New System.IO.StreamReader(resp)
        'Dim t = reader.ReadToEnd
    End Sub

    'Private Function GetRequest(ByVal url As [String], ByVal nameValueCollection As Specialized.NameValueCollection) As HttpWebRequest
    '    ' Here we convert the nameValueCollection to POST data.
    '    ' This will only work if nameValueCollection contains some items.
    '    Dim parameters = New StringBuilder()

    '    For Each key In nameValueCollection
    '        parameters.AppendFormat("{0}={1}&", HttpUtility.UrlEncode(key), HttpUtility.UrlEncode(nameValueCollection(key)))
    '    Next

    '    parameters.Length -= 1

    '    ' Here we create the request and write the POST data to it.
    '    Dim request = DirectCast(HttpWebRequest.Create(url), HttpWebRequest)
    '    request.ContentType = "application/x-www-form-urlencoded"
    '    request.Method = "POST"
    '    request.AutomaticDecompression = System.Net.DecompressionMethods.GZip
    '    request.Proxy = New System.Net.WebProxy("119.82.113.131", 3128)
    '    'Accept-Encoding: gzip,deflate
    '    Using writer = New StreamWriter(request.GetRequestStream())
    '        writer.Write(parameters.ToString())
    '    End Using

    '    Return request
    'End Function

    'Shared Function ParseEnrollmentNumbers(ByVal s As String) As List(Of String)

    '    Dim rx = System.Text.RegularExpressions.Regex.Matches(s, "\d{9}")

    '    Dim st = (From t As RegularExpressions.Match In rx Select t.Value).ToList

    '    Return st

    'End Function

    'Function fetchRCCodes() As List(Of String)
    '    'Dim req = GetRequest("http://others.ignou.ac.in/tedec11/AttendenceHall1211/ExamAttendenceList.asp", Nothing)

    '    'Dim resp = req.GetResponse.GetResponseStream()

    '    'Dim reader As New System.IO.StreamReader(resp)
    '    Dim lst As New List(Of String)
    '    Dim wc As New System.Net.WebClient
    '    Dim t = wc.DownloadString("http://others.ignou.ac.in/tedec11/AttendenceHall1211/ExamAttendenceList.asp") 'reader.ReadToEnd

    '    Dim rx = System.Text.RegularExpressions.Regex.Matches(t, "<option[^>]*?>.*?</option>")

    '    For Each i As RegularExpressions.Match In rx

    '        Dim matchValue = i.Value

    '        matchValue = System.Text.RegularExpressions.Regex.Replace(matchValue, "<[^>]*>", "")    'replace all the html elements
    '        lst.add(matchValue)
    '    Next

    '    Return lst

    'End Function


    'Function fetchRCECCodes(ByVal rcCode As String) As IgnouRegionalCenterCode
    '    Dim nv As New Specialized.NameValueCollection

    '    nv.Add("Reg_Code", rcCode)
    '    nv.Add("EC_Code", "")

    '    Dim req = GetRequest("http://others.ignou.ac.in/tedec11/AttendenceHall1211/ExamAttendenceList.asp", nv)

    '    Dim resp = req.GetResponse.GetResponseStream()

    '    Dim reader As New System.IO.StreamReader(resp)

    '    Dim t = reader.ReadToEnd

    '    t = System.Text.RegularExpressions.Regex.Replace(t, "\n|\r", "")

    '    Dim rxComboBox = System.Text.RegularExpressions.Regex.Match(t, "<select name=EC_Code>.*</select>")

    '    Dim value = rxComboBox.Value

    '    Dim rx = System.Text.RegularExpressions.Regex.Matches(value, "<option[^>]*?>.*?</option>")

    '    Dim lst As New IgnouRegionalCenterCode

    '    lst.RCCode = rcCode

    '    For Each i As RegularExpressions.Match In rx

    '        Dim matchValue = i.Value

    '        matchValue = System.Text.RegularExpressions.Regex.Replace(matchValue, "<[^>]*>", "")    'replace all the html elements

    '        lst.ECCode.Add(matchValue)
    '    Next

    '    Return lst

    'End Function

End Class

Public Class IgnouRegionalCenterCode
    Property RCCode As String
    Property ECCode As New List(Of String)
End Class
